package com.fashiontextile.user.feign;

import com.fashiontextile.common.entity.R;
import com.fashiontextile.user.entity.Image;
import com.fashiontextile.user.entity.Role;
import com.fashiontextile.user.entity.User;
import com.fashiontextile.user.feign.fallback.UserClientFallbackFactory;
import feign.RequestLine;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author brooke_zb
 */
@FeignClient(value = "fs-user", fallbackFactory = UserClientFallbackFactory.class)
public interface UserClient {
    @GetMapping("/uid/{uid:\\d+}")
    R<User> getUserByUid(@PathVariable("uid") long uid);

    @GetMapping("/username/{username}")
    R<User> getUserByUsername(@PathVariable("username") String username);

    @GetMapping("/email/{email}")
    R<User> getUserByEmail(@PathVariable("email") String email);

    @PostMapping("/user")
    R<?> insertUser(@RequestBody User user);

    @GetMapping("/role/rid/{rid:\\d+}")
    R<Role> getRoleByRid(@PathVariable("rid") Integer rid);

    @GetMapping("/role/name/{name}")
    R<Role> getRoleByName(@PathVariable("name") String name);

    @PutMapping("/user/uid/{uid:\\d+}/rid/{rid:\\d+}")
    R<?> changeRoleByUid(@PathVariable("uid") long uid, @PathVariable("rid") Integer rid);

    // 图片API
    @GetMapping("/image/type/{diid}/pointto/{pointTo}")
    R<?> getImageById(@PathVariable("pointTo") Long pointTo, @PathVariable("diid") Long diid);

    @PostMapping("/image/type/{diid}")
    R<?> uploadImage(@PathVariable("diid") Long diid, @RequestPart("picture") MultipartFile picture);

    @PostMapping("/image")
    R<?> uploadImage(@RequestBody List<Image> images);

    @DeleteMapping("/image/type/{diid}/pointto/{pointTo}")
    R<?> deleteImageByPointTo(@PathVariable("pointTo") Long pointTo, @PathVariable("diid") Long diid);

    @DeleteMapping("/image/id/{id}")
    R<?> deleteImageById(@PathVariable("id") Long id);
}
